//无序 不重复
//基于HashMap，快速定位（哈希表）
package com.itheima;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

public class HashSetDemo {
    public static void main(String[] args) {
        //功能：去重
        ArrayList<String> list = new ArrayList<>();
        list.add("A");
        list.add("A");
        list.add("A");
        System.out.println(list);
        ArrayList<String> newList = new ArrayList<>(new HashSet<>(list)) ;
        System.out.println(newList);

        // 添加元素
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("A");
        hashSet.add("B");
        hashSet.add("C");
        hashSet.add("D");
        System.out.println(hashSet);
        //迭代器Iterator
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        //增强for循环(包装Iterator)
        for(String name:hashSet){
            System.out.println(name);
        }
        //Lambda表达式
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        hashSet.forEach(s-> System.out.println(s));

        hashSet.forEach(System.out::println);
    }
}
